import sim, sim_items, main
from util import *
import random

class HydragyralPrefix(sim_items.Prefix):
    """
    "hydragyral" prefix gives affected weapon increased max damage bonus,
    decreased attack energy, and increased weight.
    TODO: should probably only affect metallic weapons
    """
    def __init__(self):
        super(HydragyralPrefix, self).__init__(
            "hydragyral", # name
            # description: (gets tacked onto item description)
            "This cleverly crafted weapon contains a hollow inner channel "
            "along its length, in which a small but heavy quantity of "
            "quicksilver flows freely. When swung, the centrifugal motion of "
            "this weighty liquid lends extra force to the blow."
        )

    def initialize(self, wearable):
        if not isinstance(wearable, sim_items.Weapon):
            raise ValueError('Tried to apply %r to non-weapon item: %r' % (self,
                wearable))

        super(HydragyralPrefix, self).initialize(wearable)

        multiplier = 0.10 + 0.1*random.random()
        multiplier2 = 0.05 + 0.1*random.random()
        self.dmgMod = multiplier * wearable.damage
        self.attackEnergyMod = multiplier2 * wearable.attackEnergy
        self.weightMod = multiplier * wearable.weight

        wearable.damage += self.dmgMod
        wearable.attackEnergy -= self.attackEnergyMod
        wearable.weight += self.weightMod

    def remove(self, wearable):
        super(HydragyralPrefix, self).remove(wearable)
        wearable.damage -= self.dmgMod
        wearable.attackEnergy += self.attackEnergyMod
        wearable.weight -= self.weightMod

#========================================
thingClass = HydragyralPrefix

